package com.zerui.manager.icc.dto;


import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Getter
@Setter
public class SubscribeEventVO {

    // 事件大类,参考事件大类枚举
    private String category;

    // 权限组
    private List<EventAuthorityVO> authorities = new ArrayList<>();

    // 是否订阅所有,仅限客户端（web，client，app）使用，0代表不订阅，1代表订阅所有authorities，报警，设备状态会过滤权限，不传不处理
    private Integer subscribeAll = 1;

    // 级联订阅,不填，没有该字段，0,代表本级，1代表下级，2代表本级+下级 ,默认值0
    private Integer domainSubscribe = 2;

    // 当前类构建器
    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        // 事件大类,参考事件大类枚举
        private String category;

        // 权限组
        private List<EventAuthorityVO> authorities = new ArrayList<>();

        // 主要分类 alarm
        public Builder category(String category) {
            this.category = category;
            return this;
        }

        // 权限组
        public Builder authority(String... authorityTypes) {
            EventAuthorityVO authorityVO = new EventAuthorityVO();
            authorityVO.setTypes(Arrays.asList(authorityTypes));
            this.authorities.add(authorityVO);
            return this;
        }

        public SubscribeEventVO build() {
            return new SubscribeEventVO(this);
        }
    }

    public SubscribeEventVO() {
        super();
    }

    public SubscribeEventVO(Builder builder) {
        this.category = builder.category;
        this.authorities = builder.authorities;
    }

    @Getter
    @Setter
    protected static class EventAuthorityVO {

        // 类型列表,没有该字段就是订阅所有，空数组代表不订阅
        private List<String> types = new ArrayList<>();

    }
}
